package com.gupaoedu.rpc;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class RpcProxyServer {
    static ExecutorService executorService = Executors.newCachedThreadPool();

    public static void publish(Object service, int port) {

        try (ServerSocket serverSocket = new ServerSocket(port)) {
            while (true) {
                Socket socket = serverSocket.accept();
                executorService.submit(new RpcProcessor(service, socket));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
